package com.example.demo.mapper;

import com.example.demo.domain.CategoryDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {

    @Select("SELECT * FROM category WHERE parent_id = 0")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "item_code",property = "itemCode"),
            @Result(column = "item_comment",property = "itemComment"),
            @Result(column = "parent_id",property = "parentId"),
            @Result(column = "gmt_create",property = "gmtCreate"),
            @Result(column = "gmt_modified",property = "gmtModified"),
    })
    List<CategoryDO> listRoots();

    @Select("SELECT * FROM category WHERE parent_id = #{parentId}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "item_code",property = "itemCode"),
            @Result(column = "item_comment",property = "itemComment"),
            @Result(column = "parent_id",property = "parentId"),
            @Result(column = "gmt_create",property = "gmtCreate"),
            @Result(column = "gmt_modified",property = "gmtModified"),
    })
    List<CategoryDO> listCategoryByParentId(@Param("parentId") Long parentId);

}
